{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Using the API to run the emulation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We use a strongly defined HTTP API protocol to communicate with a C12 backend (get and receive the data). This tutorial will briefly present basic API calls that can be used for communication with the C12 backend. Our APIs are the low-level access to our emulator, and could be made compatible with other quantum computer frameworks and interfaces.\n", "\n", "To run each API, we need to pass the unique bearer token that will be used to verify the user's right to access C12's system.\n", "\n", "For communication with C12's system, it is possible to use the API library that encapsulates the HTTP communication with the C12 system using the Python request module.\n", "\n", "To start using it, we need to create an instance of the Request class, as shown in the following code snippet." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-11-21T10:40:23.180051Z", "start_time": "2023-11-21T10:40:23.178396Z" } }, "outputs": [], "source": [ "# Installing the c12simulator-clients package (for more details see jupyter 1)\n", "import os\n", "from c12_callisto_clients.api.client import Request\n", "\n", "TOKEN = os.getenv(\"C12_TOKEN\")\n", "\n", "\n", "# Create the request instance\n", "# Constructor of the Request class also accepts the verbose parameter, which can be use for more detailed output of the methods.\n", "\n", "request = Request(auth_token=TOKEN, verbose=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Run the simulation\n", "\n", "The method `start_job()` is used to start the simulation. It has the following arguments:\n", "- `qasm_str`: QASM string with quantum circuit\n", "- `shots`: Number of trials for the simulation\n", "- `result`: what is desired output (statevector, counts, density_matrix)\n", "- `backend_name`: the name of the backend to run on" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "('176f1988-e3a8-4b8b-8323-a4684d62943a', 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[2];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\n')\n" ] } ], "source": [ "from qiskit import QuantumCircuit\n", "\n", "circuit = QuantumCircuit(2)\n", "circuit.h(0)\n", "circuit.cx(0, 1)\n", "\n", "\n", "qasm_str = circuit.qasm()\n", "res = request.start_job(\n", " qasm_str=qasm_str, shots=100, result=\"density_matrix\", backend_name=\"c12sim-iswap\"\n", ")\n", "\n", "# The function returns the UUID and QasmStr of started job or HTTP error in case of problems\n", "print(res)\n", "job_uuid = res[0]\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Get the results of a simulation\n", "\n", "To get the emulation results, we can use the `get_job_result()` method that accepts one mandatory argument (job UUID string) and two optional ones.\n", "- `timeout`, which represents the number of seconds that the function will wait for job completion\n", "- `wait`, number of seconds between each check if the job is finished\n", "\n", "If we do not specify a timeout argument the function will run until the result is obtained" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'status': 'FINISHED', 'results': {'density_matrix': [['(0.4990637768053288+1.3551869826774539e-21j)', '(0.00010967621893653856+0.0001964744471174757j)', '(-1.2293983629452221e-05+0.0002125517091276997j)', '(0.4983895890488784-0.00020246473017107892j)'], ['(0.00010967621893652468-0.00019647444711747572j)', '(0.0006796467390991628-2.032942735425706e-21j)', '(5.139379161905877e-05+4.017392210456757e-05j)', '(1.3313268045392346e-05-3.129665779283896e-05j)'], ['(-1.2293983629424465e-05-0.0002125517091276997j)', '(5.139379161905877e-05-4.017392210456757e-05j)', '(0.0010610935097781216+1.3551890535914957e-21j)', '(7.144323329608127e-05+0.00012217004103256572j)'], ['(0.4983895890488784+0.00020246473017107892j)', '(1.3313268045378468e-05+3.129665779283896e-05j)', '(7.144323329606739e-05-0.00012217004103256575j)', '(0.4991954829457991-2.0329406645084996e-21j)']]}, 'errors': ''}\n" ] } ], "source": [ "job_result = request.get_job_result(job_uuid, timeout=120, wait=5)\n", "print(job_result)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Get the status of the job" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "finished\n" ] } ], "source": [ "status = request.get_job_status(job_uuid=job_uuid)\n", "print(status)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Get all jobs\n", "\n", "Method `get_user_jobs()` can be used for obtaining information about all the jobs that have been run on the system for the user whose token is passed to the Request instance.\n", "\n", "The method has two arguments:\n", "- `limit`: an integer that represents the number of results to obtain\n", "- `offset`: an integer that represents the offset from the first result\n", "\n", "Using these two values, one can obtain the pagination, where the offset represents a page and limits the number of results per page. Method returns an array with results.\n" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "{'uuid': 'a7fadc44-22f7-42a1-9056-cd05f510a279', 'time': '2023-09-19T15:37:51.654241', 'status': 'finished', 'options': {'shots': 10000, 'result': 'counts,statevector', 'basis': 'iswap'}, 'task': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[2];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\n', 'task_orig': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg q[2];\\nh q[0];\\ncx q[0],q[1];\\n', 'errors': '4', 'result': '4'}\n", "2\n", "{'uuid': '7b646f18-198d-40d7-a3f1-cb87cb6cc7a7', 'time': '2023-09-19T15:38:08.722888', 'status': 'finished', 'options': {'shots': 10000, 'result': 'counts,statevector', 'basis': 'iswap'}, 'task': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[2];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\n', 'task_orig': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg q[2];\\nh q[0];\\ncx q[0],q[1];\\n', 'errors': '1', 'result': '8'}\n", "3\n", "{'uuid': 'c62fe639-e53a-49ec-bc15-c0d7284d723a', 'time': '2023-09-19T15:40:06.249481', 'status': 'finished', 'options': {'shots': 10000, 'result': 'counts,statevector', 'basis': 'iswap'}, 'task': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[2];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\n', 'task_orig': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg q[2];\\nh q[0];\\ncx q[0],q[1];\\n', 'errors': '3', 'result': '9'}\n", "4\n", "{'uuid': '56497e19-2105-484f-a6e6-23f29445030e', 'time': '2023-09-19T15:40:16.657476', 'status': 'finished', 'options': {'shots': 10000, 'result': 'counts,statevector', 'basis': 'iswap'}, 'task': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[2];\\nrz(-pi) q[0];\\nrz(-pi) q[1];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(-pi/2) q[1];\\nry(pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\n', 'task_orig': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg q[2];\\nh q[1];\\nh q[0];\\nx q[1];\\nx q[0];\\ncz q[0],q[1];\\nx q[0];\\nx q[1];\\nh q[0];\\nh q[1];\\nz q[0];\\nz q[1];\\ncz q[0],q[1];\\nh q[0];\\nh q[1];\\n', 'errors': '1', 'result': '9'}\n", "5\n", "{'uuid': 'd369dceb-2bf0-42ae-9fc0-eba869e388a2', 'time': '2023-09-19T15:42:37.525781', 'status': 'finished', 'options': {'shots': 1024, 'result': 'counts,statevector', 'basis': 'iswap'}, 'task': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[2];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\n', 'task_orig': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg q[2];\\nh q[0];\\ncx q[0],q[1];\\n', 'errors': 'e', 'result': 'b'}\n", "6\n", "{'uuid': '72fc139b-7d58-429a-806d-9030b90fd155', 'time': '2023-09-19T15:42:41.259799', 'status': 'finished', 'options': {'shots': 1024, 'result': 'counts,statevector', 'basis': 'iswap'}, 'task': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[2];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\n', 'task_orig': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg q[2];\\nh q[0];\\ncx q[0],q[1];\\n', 'errors': '9', 'result': 'b'}\n", "7\n", "{'uuid': '0281d8f6-7ba7-49e8-97d7-8e0ee2b6da32', 'time': '2023-09-19T15:42:49.650467', 'status': 'finished', 'options': {'shots': 1024, 'result': 'counts,statevector', 'basis': 'iswap'}, 'task': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[2];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\n', 'task_orig': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg q[2];\\nh q[0];\\ncx q[0],q[1];\\n', 'errors': 'f', 'result': '6'}\n", "8\n", "{'uuid': '259c317d-8a14-433e-a6d0-4595da57bbc8', 'time': '2023-09-19T15:43:09.545480', 'status': 'finished', 'options': {'shots': 1024, 'result': 'counts,statevector', 'basis': 'iswap'}, 'task': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[2];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\n', 'task_orig': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg q[2];\\nh q[0];\\ncx q[0],q[1];\\n', 'errors': '7', 'result': 'd'}\n", "9\n", "{'uuid': '901a0c54-47bd-4caf-9130-dadb11ffc020', 'time': '2023-09-19T15:43:09.809755', 'status': 'finished', 'options': {'shots': 1024, 'result': 'counts,statevector', 'basis': 'iswap'}, 'task': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[3];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\nry(-pi/2) q[2];\\n', 'task_orig': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg q[3];\\nh q[0];\\ncx q[0],q[1];\\nx q[2];\\nh q[2];\\n', 'errors': '5', 'result': '4'}\n", "10\n", "{'uuid': '41d70035-4510-42a1-b8a9-20128bae359f', 'time': '2023-09-19T15:45:17.122747', 'status': 'finished', 'options': {'shots': 100, 'result': 'density_matrix', 'basis': 'iswap'}, 'task': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[2];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\n', 'task_orig': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg q[2];\\nh q[0];\\ncx q[0],q[1];\\n', 'errors': '3', 'result': '5'}\n", "11\n", "{'uuid': '80bd125a-09f3-4a54-98c9-7bdad0b8e096', 'time': '2023-09-19T15:46:02.350335', 'status': 'finished', 'options': {'shots': 10000, 'result': 'counts,statevector', 'basis': 'iswap'}, 'task': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[2];\\nry(pi/2) q[0];\\nrx(pi) q[0];\\nbarrier q[0],q[1];\\nry(pi/2) q[0];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\nbarrier q[0],q[1];\\nrx(pi) q[1];\\n', 'task_orig': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg q[2];\\nh q[0];\\nbarrier q[0],q[1];\\ncx q[0],q[1];\\nbarrier q[0],q[1];\\nx q[1];\\n', 'errors': '5', 'result': 'a'}\n", "12\n", "{'uuid': 'ffb8e2ff-307a-4f02-8063-13b950a8dafe', 'time': '2023-09-19T15:55:53.406347', 'status': 'finished', 'options': {'shots': 1024, 'result': 'counts,statevector,density_matrix', 'basis': 'iswap'}, 'task': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[2];\\nry(-pi/2) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\n', 'task_orig': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\n\\nqreg q[2];\\nx q[0];\\ncx q[0],q[1];\\n', 'errors': 'f', 'result': 'f'}\n", "13\n", "{'uuid': 'd8687ad0-29d4-4b37-b55a-beda3373dbb5', 'time': '2023-09-20T08:17:01.707796', 'status': 'finished', 'options': {'shots': 10000, 'result': 'counts,statevector', 'basis': 'iswap'}, 'task': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[2];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\n', 'task_orig': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg q[2];\\nh q[0];\\ncx q[0],q[1];\\n', 'errors': 'd', 'result': '0'}\n", "14\n", "{'uuid': 'd962bed0-9893-4995-ab59-8cda94b3e238', 'time': '2023-09-20T08:17:17.385394', 'status': 'finished', 'options': {'shots': 10000, 'result': 'counts,statevector', 'basis': 'iswap'}, 'task': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[2];\\nrz(-pi) q[0];\\nrz(-pi) q[1];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(-pi/2) q[1];\\nry(pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\n', 'task_orig': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg q[2];\\nh q[1];\\nh q[0];\\nx q[1];\\nx q[0];\\ncz q[0],q[1];\\nx q[0];\\nx q[1];\\nh q[0];\\nh q[1];\\nz q[0];\\nz q[1];\\ncz q[0],q[1];\\nh q[0];\\nh q[1];\\n', 'errors': 'd', 'result': '0'}\n", "15\n", "{'uuid': '98a54d07-353b-42c4-ae20-b95a63fbe8ea', 'time': '2023-09-20T08:17:36.466371', 'status': 'finished', 'options': {'shots': 1024, 'result': 'counts,statevector', 'basis': 'iswap'}, 'task': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[2];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\n', 'task_orig': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg q[2];\\nh q[0];\\ncx q[0],q[1];\\n', 'errors': '0', 'result': '7'}\n", "16\n", "{'uuid': 'b96ada11-0cb8-4ba3-a6a0-8169fe233ce5', 'time': '2023-09-20T08:17:40.278305', 'status': 'finished', 'options': {'shots': 1024, 'result': 'counts,statevector', 'basis': 'iswap'}, 'task': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[2];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\n', 'task_orig': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg q[2];\\nh q[0];\\ncx q[0],q[1];\\n', 'errors': '1', 'result': '1'}\n", "17\n", "{'uuid': 'c83e9dd9-474a-489a-b6f2-af372304eb28', 'time': '2023-09-20T08:17:49.885408', 'status': 'finished', 'options': {'shots': 1024, 'result': 'counts,statevector', 'basis': 'iswap'}, 'task': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[2];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\n', 'task_orig': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg q[2];\\nh q[0];\\ncx q[0],q[1];\\n', 'errors': 'd', 'result': '9'}\n", "18\n", "{'uuid': '87cf6476-5366-4b97-be21-b038525e1b56', 'time': '2023-09-20T08:18:07.597540', 'status': 'finished', 'options': {'shots': 1024, 'result': 'counts,statevector', 'basis': 'iswap'}, 'task': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[2];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\n', 'task_orig': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg q[2];\\nh q[0];\\ncx q[0],q[1];\\n', 'errors': '7', 'result': '6'}\n", "19\n", "{'uuid': 'aa55dc98-b662-452c-b45b-15ff4145d066', 'time': '2023-09-20T08:18:07.705100', 'status': 'finished', 'options': {'shots': 1024, 'result': 'counts,statevector', 'basis': 'iswap'}, 'task': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[3];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\nry(-pi/2) q[2];\\n', 'task_orig': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg q[3];\\nh q[0];\\ncx q[0],q[1];\\nx q[2];\\nh q[2];\\n', 'errors': '9', 'result': '8'}\n", "20\n", "{'uuid': '176f1988-e3a8-4b8b-8323-a4684d62943a', 'time': '2023-09-20T08:18:20.655037', 'status': 'finished', 'options': {'shots': 100, 'result': 'density_matrix', 'basis': 'iswap'}, 'task': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[2];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\n', 'task_orig': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg q[2];\\nh q[0];\\ncx q[0],q[1];\\n', 'errors': '8', 'result': '8'}\n" ] } ], "source": [ "number_of_results = 5 # Limit parameter, number of records to retrieve\n", "offset = 0\n", "count = 1\n", "while True:\n", " jobs = request.get_user_jobs(limit=number_of_results, offset=offset)\n", "\n", " for job in jobs:\n", " print(f\"{count:}\")\n", " print(job)\n", " count += 1\n", "\n", " if len(jobs) < number_of_results:\n", " break\n", "\n", " offset += number_of_results" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Get information about a specific job\n", "\n", "Using the method `get_job()` it is possible to retrieve the information about the specific job with a given UUID." ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'uuid': '176f1988-e3a8-4b8b-8323-a4684d62943a', 'time': '2023-09-20T08:18:20.655037', 'status': 'finished', 'options': {'shots': 100, 'result': 'density_matrix', 'basis': 'iswap'}, 'task': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }\\nqreg q[2];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nrx(pi) q[0];\\nry(-pi/2) q[1];\\niswap q[0],q[1];\\nry(-pi/2) q[0];\\nrz(-pi/2) q[0];\\nrz(pi/2) q[1];\\nry(-pi/2) q[1];\\n', 'task_orig': 'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\nqreg q[2];\\nh q[0];\\ncx q[0],q[1];\\n', 'errors': '', 'result': {'statevector': ['(0.4990637768053288+1.3551869826774539e-21j)', '(0.0006796467390991628-2.032942735425706e-21j)', '(0.0010610935097781216+1.3551890535914957e-21j)', '(0.4991954829457991-2.0329406645084996e-21j)'], 'density_matrix': [['(0.4990637768053288+1.3551869826774539e-21j)', '(0.00010967621893653856+0.0001964744471174757j)', '(-1.2293983629452221e-05+0.0002125517091276997j)', '(0.4983895890488784-0.00020246473017107892j)'], ['(0.00010967621893652468-0.00019647444711747572j)', '(0.0006796467390991628-2.032942735425706e-21j)', '(5.139379161905877e-05+4.017392210456757e-05j)', '(1.3313268045392346e-05-3.129665779283896e-05j)'], ['(-1.2293983629424465e-05-0.0002125517091276997j)', '(5.139379161905877e-05-4.017392210456757e-05j)', '(0.0010610935097781216+1.3551890535914957e-21j)', '(7.144323329608127e-05+0.00012217004103256572j)'], ['(0.4983895890488784+0.00020246473017107892j)', '(1.3313268045378468e-05+3.129665779283896e-05j)', '(7.144323329606739e-05-0.00012217004103256575j)', '(0.4991954829457991-2.0329406645084996e-21j)']], 'counts': {'00': 46, '11': 54}, 'states': {'density_matrix': {}, 'statevector': {}}}}\n" ] } ], "source": [ "job_data = request.get_job(job_uuid)\n", "print(job_data)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.13" } }, "nbformat": 4, "nbformat_minor": 4 }